package org.sfx.util

import java.io.PrintWriter
import scala.tools.nsc.interpreter.IMain
import scala.tools.nsc.Settings
import javafx.beans.property._
import java.net._
import java.io.File
import javafx.beans.value.WritableValue
import org.sfx.rich.Enrich._
import org.sfx.io.NullWriter
import javafx.beans.value.ObservableValue
import javafx.beans.value.ObservableBooleanValue

object InterpreterSettings extends Settings() {
  for (url <- getClass().getClassLoader().asInstanceOf[URLClassLoader].getURLs()) {
    this.classpath.append(new File(url.toURI()).toString())
  }
}

object Interpreter extends IMain(InterpreterSettings, new PrintWriter(NullWriter)) {
  def manifestOf[T](implicit m: Manifest[T]): Manifest[T] = m
  
  import java.util.{List => JList}
  
  trait ListOfBoolean extends JList[Boolean]
  
  def main(args: Array[String]): Unit = {
    import scala.tools.nsc.interpreter.Results._
    assert(interpret("val _moo_ : " + manifestOf[JList[Boolean]] + " = null.asInstanceOf[" + manifestOf[JList[Boolean]] + "]") == Success)
    assert(interpret("val _moo_ : " + manifestOf[JList[Boolean]] + " = null.asInstanceOf[" + manifestOf[ListOfBoolean] + "]") != Success)
    bind("m1", null.asInstanceOf[JList[Boolean]])(manifestOf[JList[Boolean]])
    bind("m2", null.asInstanceOf[JList[Boolean]])(manifestOf[JList[Boolean]])
    /*println(manifestOf[WritableValue[Int]] <::< manifestOf[WritableValue[Int]])
    println(manifestOf[SimpleIntegerProperty] <::< manifestOf[WritableValue[java.lang.Integer]])
    println(manifestOf[SimpleBooleanProperty] <::< manifestOf[ObservableValue[java.lang.Boolean]])
    val x: SimpleBooleanProperty = null
    val y: ObservableValue[java.lang.Boolean] = null
    var yy = y
    yy = x*/
    //bind("observable", observable)
    //interpret("var temp = observable")
    //interpret("temp = new javafx.beans.property.SimpleObjectProperty()")
    //interpret("observable.setValue(true)")
    //interpret("observable.getValue()")
  }
}
